//
//  MLDTableController.swift
//  Sina
//
//  Created by 万世豪情 on 15/10/9.
//  Copyright © 2015年 万世豪情. All rights reserved.
//

import UIKit

class MLDTableController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tab = MLDTabBar()
        
        setValue(tab, forKey: "tabBar")
        
        addChildViewController(MLDHomeViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(MLDMessageViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(MLDDiscoverViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(MLDProfileViewController(), title: "我", imageName: "tabbar_profile")
        // Do any additional setup after loading the view.
    }

    private func addChildViewController(childController: UIViewController, title: String, imageName: String) {
        //设置标题
        childController.title = title
        
        //设置图片
        childController.tabBarItem.image = UIImage(named:imageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        //选中模式图片
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //图片位置
        childController.tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0)
        
        //设置文字颜色
        let textColorAttr = [
        NSForegroundColorAttributeName:UIColor.orangeColor()
        ]
        
        childController.tabBarItem.setTitleTextAttributes(textColorAttr, forState: UIControlState.Selected)
        
        //初始化导航控制器
        let nav = MLDNavigationController(rootViewController: childController)
        
        addChildViewController(nav)
        
    }
    
   }
